<template>
	<view class="w-100">
		<anil-seat @confirm="confirm" ref="anilSeat" :max="4" :title="filmInfo.name"
			:info="`${showInfo.showTime}${filmInfo.filmTypes}`" :room-name="showInfo.hallName" :seatData="seatData">
		</anil-seat>
	</view>
</template>
<script>
	import anilSeat from '@/uni_modules/anil-seat/components/anil-seat/anil-seat.vue'
	export default {
		components: {
			anilSeat
		},
		data() {
			return {
				seatData: [

				],
				showid: 0,

				filmInfo: {
					name: '加载中...',
					filmTypes: '加载中...',
				},
				showInfo: {
					showTime: '加载中...',
					hallName: '加载中...'
				},

				cinemaName: '',
				cinemaId: '',
				
				cinemaAddress:'',
			};
		},
		computed: {

		},
		onLoad(option) {
			this.showid = option.showid
			this.cinemaName = option.cinemaName
			this.cinemaId = option.cinemaId
			this.cinemaAddress = option.cinemaAddress
			// 座位图初始化 - seatData座位数据
			this.getList()
		},
		methods: {
			getList() {
				this.request.httpTokenRequest({
					url: "movie/getShowSeats",
					method: "get"
				}, {
					showid: this.showid
				}).then(res => {
					if (res.code == 0) {
						this.filmInfo = res.data.filmInfo
						this.showInfo = res.data.showInfo
						res.data.seatsInfo.seats.forEach(item => {
							this.seatData.push({
								"YCoord": item.rowNo, // -Y坐标
								"XCoord": item.columnNo, // -X坐标
								"SeatCode": item.seatId, // 座位code
								"Status": item.status == 'N' ? 1 : 0, // 座位状态
								"RowNum": item.columnNo, // 排
								"ColumnNum": item.rowNo, // 列
								"Price": item.salePrice // 当前座位票价
							})
						})
						this.$refs['anilSeat'].initData(this.seatData)
					} else {
						this.$util.msg(res.msg)
					}
				}, error => {})
			},

			confirm(e) {
				let seat;
				let mobile = uni.getStorageSync('user').mobile
				let price = 0
				let arr = []
				let seat_arr = []

				e.forEach(item => {
					price += Number(item.Price)
					seat_arr.push({
						ColumnNum: item.ColumnNum,
						RowNum: item.RowNum
					})
				})
				if (e.length <= 1) {
					seat = e[0].SeatCode
				} else {
					e.forEach(item => {
						arr.push(item.SeatCode)
					})
					seat = arr.join(',')
				}

				let info = {
					cinemaId: this.cinemaId,
					scenicName: this.cinemaName,
					filmName: this.filmInfo.name,
					hallName: this.showInfo.hallName,
					pic: this.filmInfo.pic,
					filmId: this.filmInfo.filmId,
					showId: this.showid,
					seatIds: seat,
					acceptChangeSeat: false,
					mobile: mobile,
					price: price,
					showTime: this.showInfo.showTime,
					duration: this.filmInfo.duration,
					seat_arr: seat_arr
				}
				info = JSON.stringify(info)
				uni.navigateTo({
					url: `/otherpages/film/create-order?info=${info}&type=${this.showInfo.showVersionType}&cinemaAddress=${this.cinemaAddress}`
				})

			}
		}
	}
</script>

<style lang="scss" scoped>

</style>